<template>
  <div>
        <Button type="primary" @click="modelAdd = true;handleReset('formValidate')">添加</Button>
        <Button type="error" @click="removes">删除多个</Button>
        <Input v-model="filter.name">
            <Button slot="append" icon="ios-search" @click = "seachData"></Button>
        </Input>
        <Table border ref="selection" @on-selection-change="onSelectionChange" :columns="columns" :data="data"></Table>
        <page :total = "total" :page-size="filter.rows" :page-size-opts="[5,10,15,20]" @on-page-size-change="onPagesizeChange" @on-change="onPage" show-sizer></page>
        <Modal
            v-model="modelAdd"
            title="Common Modal dialog box title">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                <FormItem label="Name" prop="name">
                    <Input v-model="formValidate.name" placeholder="Enter your name"></Input>
                </FormItem>
                <FormItem label="Password" prop="password">
                    <Input v-model="formValidate.password" placeholder="Enter your password"></Input>
                </FormItem>
                 <FormItem label="Age" prop="age">
                    <Input v-model="formValidate.age" placeholder="Enter your age"></Input>
                </FormItem> 
            </Form>
             <div slot="footer">
                    <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
                    <Button type="ghost" @click="handleReset('formValidate')">重置</Button>
            </div>
        </Modal>
  </div>
      
</template>
<script>
    import {dataMixins}  from '../common/dataMixins';
    export default {
        mixins : [dataMixins],
        data () {
            return {
              modules:'users',
              formValidate: {
                    name: '',
                    password:'',
                    age:''
                },
                ruleValidate: {
                    name: [
                        { required: true, message: 'The name cannot be empty', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: 'The password cannot be empty', trigger: 'blur' }
                    ],
                    age: [
                        { required: true, message: 'The age cannot be empty', trigger: 'blur' }
                    ]
                },
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: 'Name',
                        key: 'name',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                    {
                      title:'Password',
                      key:'password'
                    },
                    {
                      title:'Age',
                      key:'age'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.editIdata(params.row._id)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => { 
                                            this.remove(params.row._id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ]
            }
        }
    }
</script>